layui.use(['jquery','form', 'ax','admin','layedit', 'laydate'], function(){
    var $ =layui.jquery
    var form = layui.form
    var layer = layui.layer
    var layedit = layui.layedit
    var laydate = layui.laydate
    var $ax = layui.ax;
    var admin = layui.admin;


    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        alert(JSON.stringify(data));
        console.log(data)
        var ajax = new $ax(Feng.ctxPath + "/myScheduleFrame/saveSframe", function (data) {
            if (data.code==400){
                Feng.error(data.message);
            } else {
                Feng.success("框架创建成功！");
                //传给上个页面，刷新table用
                admin.putTempData('formOk', true);
                //关掉对话框
                admin.closeThisDialog();
                parent.location.href="/myScheduleFrame/showMyScheduleFrame";
            }
        }, function (data) {
            Feng.error("框架！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        //添加 return false 可成功跳转页面
        return false;
    });



    $(document).on('click', '#sframeItemAddBtn', function() {

        var htmladd="";
        htmladd+="        <div class=\"layui-card\" id=\"Mess\">\n" +
            "            <div class=\"layui-card-header\">日程框架项信息</div>\n" +
            "            <div class=\"layui-card-body\">\n" +
            "                <div class=\"layui-form-item layui-row\">\n" +
            "                    <input name=\"userId\" type=\"hidden\"/>\n" +
            "                    <div class=\"layui-inline layui-col-md12\">\n" +
            "                        <label class=\"layui-form-label\">框架项序号<span style=\"color: red;\">*</span></label>\n" +
            "                        <div class=\"layui-input-block\">\n" +
            "                            <input name=\"serial[]\" placeholder=\"请输入框架项序号\" type=\"text\" class=\"layui-input\" lay-verify=\"required\" required/>\n" +
            "                        </div>\n" +
            "                    </div>\n" +
            "                    <div class=\"layui-inline layui-col-md12\">\n" +
            "                        <label class=\"layui-form-label\">框架项名称<span style=\"color: red;\">*</span></label>\n" +
            "                        <div class=\"layui-input-block\">\n" +
            "                            <input name=\"scheduleItemName[]\" placeholder=\"请输入框架项名称\" type=\"text\" class=\"layui-input\" lay-verify=\"required\" required/>\n" +
            "                        </div>\n" +
            "                    </div>\n" +
            "                    <div class=\"layui-inline layui-col-md12\">\n" +
            "                        <label class=\"layui-form-label\">开始时间</label>\n" +
            "                        <div class=\"layui-input-inline\">\n" +
            "                            <input  name=\"startTime[]\" placeholder=\"请选择框架项的开始时间\" type=\"text\"  class=\"layui-input date-icon dataOnlyTime\" autocomplete=\"off\"/>\n" +
            "                        </div>\n" +
            "                        <label class=\"layui-form-label\">结束时间</label>\n" +
            "                        <div class=\"layui-input-inline\">\n" +
            "                            <input  name=\"stopTime[]\" placeholder=\"请选择框架的结束时间\" type=\"text\"  class=\"layui-input date-icon dataOnlyTime\" autocomplete=\"off\"/>\n" +
            "                        </div>\n" +
            "                    </div>\n" +
            "                </div>\n" +
            "            </div>\n" +
            "        </div>"


        $("#sframeItemMess").append(htmladd);
        showData();
        showTime();
       /* form.render();*/
    });

    //删除最后一个框架项框架
    $(document).on('click', '#sframeItemDelBtn', function() {

        $("#Mess:last").remove();
    });


    function showData(){
        lay('.datatime').each(function () {
            //时间范围
            laydate.render({
                elem: this,
                trigger: 'click'
            });
        });
    }

    function showTime(){
        lay('.dataOnlyTime').each(function () {
            //时间范围
            laydate.render({
                elem: this,
                trigger: 'click'
                ,type: 'time'
            });
        });
    }

    //渲染时间
    showData();
    showTime();








});
